package com.net.tomcat5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 只支持get请求，post有错误
 *
 * @author jiangbang
 * @date 2016/8/24
 */
public class Server {
    private ServerSocket server;


    public static void main(String[] args) {
        Server server = new Server();
        server.start();
    }

    //启动方法
    public void start(){
        try {
             server = new ServerSocket(8888);
            this.receive();
        } catch (IOException e) {
        }
    }
    //结束方法
    public void stop(){

    }

    //接受客户端
    private void receive(){
        try {
            Socket client = server.accept();
            StringBuilder sb = new StringBuilder();
            String msg = null; //接受客户端的请求信息
            BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
            while((msg=br.readLine()).length()>0){
                sb.append(msg);
                sb.append("\r\n");
                if(null==msg){
                    break;
                }
            }
            System.out.println(sb.toString());
        } catch (IOException e) {

        }
    }
}
